import java.util.Scanner;

//给出一个字符串，并按照前序遍历，得到二叉树，在通过中序遍历打印出来
class TreeNode{
    public char val;
    public TreeNode left;
    public TreeNode right;

    public TreeNode(char val) {
        this.val = val;
    }
}
public class Text3 {
    public static int i=0;
    public static  TreeNode createTree(String str){
        TreeNode root=null;
        if (str.charAt(i)!='#'){
            root=new TreeNode(str.charAt(i));
            i++;
            root.left=createTree(str);
            root.right=createTree(str);
        }else {
            i++;
        }
        return root;
    }
    public static void inOrder(TreeNode rood){
        if (rood==null){
            return;
        }
        inOrder(rood.left);
        System.out.println(rood.val+" ");
        inOrder(rood.right);
    }
    public static void main(String[] args) {
        //String arr="ABC##DE#G##F###";
        Scanner scanner=new Scanner(System.in);
        while (scanner.hasNextLine()){
            String str=scanner.nextLine();
            TreeNode ret=createTree(str);
            inOrder(ret);
        }

    }
}
